﻿

#include "pch.h"
#include "framework.h"
#include "MFCApplication2.h"
#include "MFCApplication2Dlg.h"
#include "CMyMonthCal.h"
#include "ColorDialog.h"
#include "BCGPWinXPVisualManager.h"
#include "MainDialog.h"
#include "BCGPPropertySheet.h"
#include "BCGPToolBarImages.h"
#include <gdiplus.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif




BEGIN_MESSAGE_MAP(CMFCApplication2App, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()




CMFCApplication2App::CMFCApplication2App(){

	/*支持重新启动管理器*/
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
	m_gdiplusToken = 0;
}



CMFCApplication2App theApp;

HICON LoadPNGAsIcon(LPCTSTR pszPath, int nWidth = 32, int nHeight = 32){

	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	Bitmap* pBitmap = new Bitmap(pszPath);
	if (pBitmap->GetLastStatus() != Ok){

		delete pBitmap;
		GdiplusShutdown(gdiplusToken);
		return NULL;
	}
	Bitmap* pResized = new Bitmap(nWidth, nHeight);
	Graphics* pGraphics = Graphics::FromImage(pResized);
	pGraphics->DrawImage(pBitmap, 0, 0, nWidth, nHeight);
	HICON hIcon;
	pResized->GetHICON(&hIcon);
	delete pGraphics;
	delete pResized;
	delete pBitmap;
	GdiplusShutdown(gdiplusToken);

	return hIcon;
}
/*CMFCApplication2App 初始化*/

BOOL CMFCApplication2App::InitInstance(){

	/*初始化GDI+*/
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	/*将它设置为包括所有要在应用程序中使用的
	公共控件类。*/
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	AfxEnableControlContainer();

	/*创建 shell 管理器，以防对话框包含
	任何 shell 树视图控件或 shell 列表视图控件。*/
	CShellManager *pShellManager = new CShellManager;

	/* 激活"Windows Native"视觉管理器，以便在 MFC 控件中启用主题*/
	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
	SetRegistryKey(L"应用程序向导生成的本地应用程序");
	CBCGPPropertySheet propSheet;
	CMFCApplication2Dlg pge1;
	ColorDialog pge2;
	propSheet.SetLook(CBCGPPropertySheet::PropSheetLook_OutlookBar);
	/*C:\\Users\\wecon\\Desktop\\t4素材\\page1.png*/
	propSheet.SetIconsList(IDB_PNG2, 32);
	pge2.m_psp.pszTitle = L"Color Controls";
	propSheet.AddPage(&pge1);
	propSheet.AddPage(&pge2);
	INT_PTR nResponse = propSheet.DoModal();

	if (nResponse == -1){

		TRACE(traceAppMsg, 0, "警告: 对话框创建失败，应用程序将意外终止。\n");
		TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件，则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
	}
	if (pShellManager != nullptr){

		delete pShellManager;
	}

#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
	ControlBarCleanUp();
#endif
	return FALSE;
}

int CMFCApplication2App::ExitInstance(){

	/* 清理GDI+*/
	if (m_gdiplusToken != 0){

		Gdiplus::GdiplusShutdown(m_gdiplusToken);
	}

	return CWinApp::ExitInstance();
}

